<template>
  <el-container class="layout">
    <el-aside :width="isOpen?'200px':'64px'">
      <div
        class="logo"
        :class="{logo_mini:!isOpen}"
      >
      </div>
      <el-menu
        :default-active='$route.path'
        router
        background-color="#002233"
        text-color="#fff"
        active-text-color="#ffd04b"
        :collapse='!isOpen'
        :collapse-transition="false"
      >
        <el-menu-item index="/">
          <i class="el-icon-menu"></i>
          <span slot="title">首页</span>
        </el-menu-item>
        <el-menu-item index="/content">
          <i class="el-icon-setting"></i>
          <span slot="title">内容管理</span>
        </el-menu-item>
        <el-menu-item index="/imags">
          <i class="el-icon-setting"></i>
          <span slot="title">素材管理</span>
        </el-menu-item>
        <el-menu-item index="/article">
          <i class="el-icon-setting"></i>
          <span slot="title">发布文章</span>
        </el-menu-item>
        <el-menu-item index="/comment">
          <i class="el-icon-setting"></i>
          <span slot="title">评论管理</span>
        </el-menu-item>
        <el-menu-item index="/fans">
          <i class="el-icon-setting"></i>
          <span slot="title">粉丝管理</span>
        </el-menu-item>
        <el-menu-item index="/seting">
          <i class="el-icon-setting"></i>
          <span slot="title">个人设置</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <span
          @click="click_aside"
          class='icon'
          :class="{'el-icon-s-fold':isOpen ,'el-icon-s-unfold':!isOpen }"
        ></span>
        <span class="text">博客园交流论坛</span>
        <el-dropdown @command="clickItem">
          <span class="el-dropdown-link">
            <img
              class="had_img"
              :src="photo"
              alt=""
            >
            <span class="name">{{name}}</span>
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              command='setting'
              icon="el-icon-setting"
            >设置</el-dropdown-item>
            <el-dropdown-item
              command='logout'
              icon="el-icon-position"
            >退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import auth from "@/utils/auth";
export default {
  name: "Layout",
  data() {
    return {
      isOpen: true,
      photo: "",
      name: ""
    };
  },
  created() {
    const { photo, name } = auth.getUser();
    (this.photo = photo), (this.name = name);
  },
  methods: {
    click_aside() {
      this.isOpen = !this.isOpen;
    },
    clickItem(command) {
      this[command]();
    },

    logout() {
      auth.delUser();
      this.$router.push("/login");
    }
  }
};
</script>

<style lang="less" scoped>
.layout {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;

  .el-aside {
    background: #002233;
    .logo {
      width: 100%;
      height: 60px;
      background: #002244 url(../assets/logo_admin.png) no-repeat center / 130px
        auto;
    }
    .logo_mini {
      width: 100%;
      height: 60px;
      background: #002244 url(../assets/logo_admin_01.png) no-repeat center /
        40px auto;
    }
  }

  .el-header {
    border-bottom: 1px solid #eeeeee;
    vertical-align: middle;
    line-height: 60px;
    .icon {
      font-size: 24px;
      vertical-align: middle;
    }

    .text {
      margin-left: 10px;
      vertical-align: middle;
    }
  }

  .el-dropdown {
    float: right;

    .had_img {
      width: 30px;
      height: 30px;
      vertical-align: middle;
    }
    .name {
      font-weight: bold;
      margin-left: 10px;
      vertical-align: middle;
    }
  }

  //   .el-main {
  //     // background: url(../assets/welcome.jpg) no-repeat center;
  //   }
}
</style>>

